package pers.brozen.anka.controller;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.brozen.anka.apis.params.category.AddCategoryParam;
import pers.brozen.anka.apis.params.category.DeleteCategoryParam;
import pers.brozen.anka.apis.vos.CategoryVo;
import pers.brozen.anka.service.CategoryService;
import pers.brozen.anka.support.web.response.Response;

import java.util.List;

/**
 * @author Brozen
 * @since 2024-05-28
 */
@RestController
@RequestMapping("/api/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;


    @GetMapping
    public Response<List<CategoryVo>> listCategories() {
        return Response.ofSuccess(categoryService.getCategories());
    }


    @PostMapping("/add")
    public Response<Void> add(@Valid @RequestBody AddCategoryParam param) {
        categoryService.addCategory(param);
        return Response.ofSuccess();
    }


    @PostMapping("/delete")
    public Response<Void> delete(@Valid @RequestBody DeleteCategoryParam param) {
        categoryService.deleteCategory(param);
        return Response.ofSuccess();
    }

}
